package com.match.plugin.disruptor.handler;

import com.hazelcast.core.HazelcastInstance;
import com.lmax.disruptor.EventHandler;
import com.match.common.model.dto.MatchOrder;
import com.match.match.MatchDetailHandler;
import com.match.plugin.hazelcast.HazelcastPlugin;

/**
 * @ClassName: OutDepthHandler
 * @Description: TODO(已挂单深度处理消费者)
 */
public class OutDepthHandler implements EventHandler<MatchOrder> {

	MatchDetailHandler matchDetailHandler = MatchDetailHandler.getMatchDetailHandler();
	HazelcastInstance hzInstance = HazelcastPlugin.hazelcastInstance;
	
	// EventHandler的方法 - 都消费
	public void onEvent(MatchOrder order, long sequence, boolean endOfBatch) throws Exception {
		//当订单是1或2时，说明吃过单，造成了出单深度变化
		if (this.isEatOrder(order)) {
//			ThreadPoolUtil.getExec().submit(new Runnable() {
//				public void run() {
					matchDetailHandler.outMatchDepth(order,hzInstance);
//				}
//			});
		}
	}
	
	//判断是否吃过单
	private Boolean isEatOrder(MatchOrder order) {
		if (order.getIsMarket()) {
			return order.getList().size()>0?true:false;
		}else {
			if (order.getState().intValue()==1||order.getState().intValue()==2) {
				return true;
			}else {
				return false;
			}
		}
	}
}
